package likouJava;

import java.util.List;
import java.util.Scanner;

public class 一元二次函数 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int[] X = new int[Q];
        for (int i = 0; i < Q; i++) {
            X[i] = sc.nextInt();
        }

        for (int i = 0; i < Q; i++) {
            long xi = X[i];
            long value = 0;
            long pow = 1;
            for (int j = 0; j < N; j++) {
                value += (long) A[j] * pow;
                pow += xi;
            }
            System.out.println(value % M);
        }
        sc.close();
    }
}



